package com.zlhj.ex.Controller;

import com.zlhj.ex.Common.Res;
import com.zlhj.ex.entity.Car;
import com.zlhj.ex.service.CarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author zsx
 * @date 2021/06/16 10:14
 */
@Controller
@RequestMapping("/car")
@Api(value = "car")
public class CarController {

    @Autowired
    private CarService carService;


    @GetMapping("/getCarList")
    @ApiOperation(value = "getCarList")
    @ResponseBody
    public Res getCarList(){
        List<Car> carList = carService.list();
        if (carList.size() > 0){
            return new Res("200","success",carList);
        } else if (carList.size() == 0){
            return new Res("数据为空");
        }
        return new Res("error");
    }


    @PostMapping("/insert")
    @ApiOperation("insert")
    @ResponseBody
    public Res insert(Car car){
        boolean save = carService.save(car);
        if (save){
            return new Res("success");
        }
        return new Res("error");
    }
}
